﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DotNetX
{
    /// <summary>
    /// A language
    /// </summary>
    public class Language
    {
        /// <summary>
        /// The name of this language
        /// </summary>
        public string Name
        {
            get
            {
                // return the name
                return this._name;
            }
            set
            {
                // set the name
                this._name = value;
            }
        }
        private string _name = string.Empty;

        /// <summary>
        /// The name local of this language in its language
        /// </summary>
        public string LocalName
        {
            get
            {
                // return the name
                return this._localName;
            }
            set
            {
                // set the name
                this._localName = value;
            }
        }
        private string _localName = string.Empty;

        /// <summary>
        /// The language code of this language
        /// </summary>
        public string Code
        {
            get
            {
                // return the code
                return this._code;
            }
            set
            {
                // set the code
                this._code = value;
            }
        }
        private string _code = string.Empty;

        /// <summary>
        /// Compares two languages
        /// </summary>
        /// <param name="language1">The first language</param>
        /// <param name="language2">The second language</param>
        /// <returns>True of the languages are the same, else false</returns>
        public static bool operator ==(Language language1, Language language2)
        {
            // is the object null?
            if (object.Equals(language1, null))
                return object.Equals(language2, null);
            if (object.Equals(language2, null))
                return object.Equals(language1, null);

            // are the languages the same?
            return language1.Code == language2.Code &&
                   language1.Name == language2.Name;
        }

        /// <summary>
        /// Compares two languages
        /// </summary>
        /// <param name="language1">The first language</param>
        /// <param name="language2">The second language</param>
        /// <returns>True of the languages are not the same, else false</returns>
        public static bool operator !=(Language language1, Language language2)
        {
            // is the object null?
            if (object.Equals(language1, null))
                return !object.Equals(language2, null);
            if (object.Equals(language2, null))
                return !object.Equals(language1, null);

            // are the languages the same?
            return language1.Code != language2.Code ||
                   language1.Name != language2.Name;
        }

        /// <summary>
        /// Constructs this language
        /// </summary>
        /// <param name="name">The name of this language</param>
        /// <param name="code">The code of this language</param>
        public Language(string name, string code)
        {
            if (name == null)
                throw new ArgumentNullException("'name' is null.");
            if (name.Length == 0)
                throw new ArgumentOutOfRangeException("'name' is zero-length.");
            if (code == null)
                throw new ArgumentNullException("'code' is null.");
            if (code.Length == 0)
                throw new ArgumentOutOfRangeException("'code' is zero-length.");

            // set the values
            this.Name = name;
            this.LocalName = name;
            this.Code = code;
        }

        /// <summary>
        /// Constructs this language
        /// </summary>
        /// <param name="name">The name of this language</param>
        /// <param name="localName">The local name of this language in this language</param>
        /// <param name="code">The code of this language</param>
        public Language(string name, string localName, string code)
        {
            if (name == null)
                throw new ArgumentNullException("'name' is null.");
            if (name.Length == 0)
                throw new ArgumentOutOfRangeException("'name' is zero-length.");
            if (localName == null)
                throw new ArgumentNullException("'localName' is null.");
            if (localName.Length == 0)
                throw new ArgumentOutOfRangeException("'localName' is zero-length.");
            if (code == null)
                throw new ArgumentNullException("'code' is null.");
            if (code.Length == 0)
                throw new ArgumentOutOfRangeException("'code' is zero-length.");

            // set the values
            this.Name = name;
            this.LocalName = localName;
            this.Code = code;
        }

        /// <summary>
        /// Tostring
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            // return the local name
            return this.LocalName;
        }
    }
}
